<template>
    <div class="doc-content-wrapper">
        <div class="doc-content-container">
            <div class="doc-content">
                <h2 class="mb-5 flex items-center">字符串分割成数组</h2>
                <Codemirror :code="splitCode1" name="split字符串分割成数组" class="mb-10" />
                <Codemirror :code="splitCode2" name="数组对象中字符串分割成数组" class="mb-10" />
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
    setup () {
        const splitCode1 = ref(`let str = "123,456,789";
let splitArr = str.split(',')

console.log(JSON.stringify(splitArr));`)

        const splitCode2 = ref(`let arr = [{
    group: "李大钊,陈洁,王小帅",
    old: "10,16,22",
    sex: "0,1,0"
},{
    group: "雷军,欧小君,彭于晏",
    old: "11,24,20",
    sex: "0,1,0"
}]

for (let prop in arr) {    // prop指对象的属性名
    for (let i in arr[prop]) {
      arr[prop][i] = arr[prop][i].split(',')
    }
}

console.log(JSON.stringify(arr));`)

        return {
            splitCode1,
            splitCode2,
        }
    }
})
</script>

<style scoped>

</style>